<script setup>
import {selectLeaveClassService,handleLeaveClassService} from '@/api/ClassManager.js'
import { ref } from 'vue'

const total = ref(0)
const params = ref({
  courseName:'',
  userName:'',
  pageNum:1,
  pageSize:5
})

const handleLeave = ref({
    id:'',
    status:''
})

const agreeClick = async (row) => {
    handleLeave.value.id=row.id
    handleLeave.value.status=1
    await handleLeaveClassService(handleLeave.value)
    ElMessage.success('成功！')
    getStudentLeaveClassList()
}
const disAgreeClick = async (row) => {
    handleLeave.value.id=row.id
    handleLeave.value.status=2
    await handleLeaveClassService(handleLeave.value)
    ElMessage.success('成功！')
    getStudentLeaveClassList()

}
const studentLeaveClassList = ref([])
const studentLeaveClassVo = ref({
      id:'',
      courseName:'',
      courseSubName:'',
      userName:'',
      status:'',
      statusStr:'',
      createTime:'',
      createTimeStr:'',
      reason:''
})

const handleCurrentChange = (page)=>{
    params.value.pageNum = page
    getStudentLeaveClassList()
}
const getStudentLeaveClassList = async()=>{
    const res = await selectLeaveClassService(params.value);
    studentLeaveClassList.value = res.data.data
    total.value = res.data.total
}
getStudentLeaveClassList()
const search = () => {
    getStudentLeaveClassList()
}
</script>

<template>
  <div>
    <div class="cus-header">
        <el-card>
            <div class="search">
                <div>
                    课程：
                    <el-input v-model="params.courseName" style="width: 240px" placeholder="请输入课程名称" />
                </div>
                <div style="margin-left: 20px;">
                    姓名：
                    <el-input v-model="params.userName" style="width: 240px" placeholder="请输入姓名" />
                </div>
                <div style="margin-left: 20px;">
                    <el-button @click="search" style="width: 80px;" type="primary">搜索</el-button>
                </div>
            </div>
            
        </el-card>
    </div>
    <div class="cus-body">
        <el-card style="min-height: 650px;">
            <el-table :data="studentLeaveClassList" style="width: 100%">
                <el-table-column fixed prop="id" label="请假编号" width="150" />
                <el-table-column prop="courseName" label="课程名称" width="120" />
                <el-table-column prop="courseSubName" label="课节名称" width="120" />
                <el-table-column prop="userName" label="学生姓名" width="120" />
                <el-table-column prop="reason" label="请假原因" width="120" />
                <el-table-column prop="statusStr" label="处理状态" width="120" />
                <el-table-column prop="createTimeStr" label="创建时间" width="600" />
                <el-table-column fixed="right" label="操作" min-width="120">
                    <template #default="{row}">
                        <el-button link type="primary" size="small" @click="agreeClick(row)">
                            同意
                        </el-button>
                        <el-button link type="primary" size="small" @click="disAgreeClick(row)">拒绝</el-button>
                    </template>
                </el-table-column>
            </el-table>
                                    <!-- 分页 -->
            <div style="margin-top: 20px;">
              <el-pagination
              v-model:current-page="params.pageNum"
              v-model:page-size="params.pageSize"
              :background="true"
              layout="jumper,prev, pager, next,total"
              :total=total
              @current-change="handleCurrentChange"
              style="justify-content: end;"
            />
             </div>
        </el-card>
    </div>
  </div>
</template>


<style lang="scss" scoped>
    .flex-row{
        display: flex;
        flex-direction: row;
    }
    .cus-header{
        .search{
            display: flex;
            flex-direction: row;
        }
    }
    .cus-body{
        margin-top: 15px;
    }
</style>